// import com.alibaba.druid.sql.ast.SQLExpr;
// import com.alibaba.druid.sql.ast.SQLObjectImpl;
// import com.alibaba.druid.sql.ast.expr.SQLBinaryOperator;
// import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLPartitionRef.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/listTran.h"
#include "../expr/SQLIdentifierExpr.h"

SQLPartitionRef_Item::SQLPartitionRef_Item()
{
}

SQLPartitionRef_Item::SQLPartitionRef_Item(SQLIdentifierExpr_ptr columnName)
{
  setColumnName(columnName);
}

// @Override
void SQLPartitionRef_Item::accept0(SQLASTVisitor_ptr v)
{
}

SQLIdentifierExpr_ptr SQLPartitionRef_Item::getColumnName()
{
  return columnName;
}

void SQLPartitionRef_Item::setColumnName(SQLIdentifierExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLPartitionRef_Item));
  }
  this->columnName = x;
}

SQLExpr_ptr SQLPartitionRef_Item::getValue()
{
  return value;
}

void SQLPartitionRef_Item::setValue(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLPartitionRef_Item));
  }
  this->value = x;
}

SQLBinaryOperator_ptr SQLPartitionRef_Item::getOperator()
{
  return operator_;
}

void SQLPartitionRef_Item::setOperator(SQLBinaryOperator_ptr operator_)
{
  this->operator_ = operator_;
}

SQLPartitionRef::SQLPartitionRef()
{
  items = std::make_shared<std::list<SQLPartitionRef_Item_ptr>>();
}
// @Override
void SQLPartitionRef::accept0(SQLASTVisitor_ptr v)
{
  if (v->visit(SharedObject(SQLPartitionRef)))
  {
    SQLObject_list_ptr tmp = ListTran::tran_class<SQLPartitionRef_Item, SQLObject>(items);
    acceptChild(v, tmp);
  }
  v->endVisit(SharedObject(SQLPartitionRef));
}

SQLPartitionRef_Item_list_ptr SQLPartitionRef::getItems()
{
  return items;
}

void SQLPartitionRef::addItem(SQLPartitionRef_Item_ptr item)
{
  item->setParent(SharedObject(SQLPartitionRef));
  items->push_back(item);
}

void SQLPartitionRef::addItem(SQLIdentifierExpr_ptr name, SQLExpr_ptr value)
{
  SQLPartitionRef_Item_ptr item = SQLPartitionRef_Item_ptr(new SQLPartitionRef_Item());
  item->setColumnName(name);
  item->setValue(value);
  item->setParent(SharedObject(SQLPartitionRef));
  this->items->push_back(item);
}
